package com.springcloud.sc.ucpv5.controller;
import java.util.List;
import java.util.Map;
import java.util.Date;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.springcloud.sc.comm.core.constant.CommonConstants;
import com.springcloud.sc.comm.core.util.R;
import com.springcloud.sc.ucp.v5.api.entity.UcpConversationRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springcloud.sc.ucpv5.service.UcpConversationRecordService;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhl
 * @since 2019-06-11
 */
@RestController
@RequestMapping("/ucpConversationRecord")
public class UcpConversationRecordController {
    @Autowired private UcpConversationRecordService ucpConversationRecordService;

    /**
    * 通过ID查询
    *
    * @param id ID
    * @return UcpConversationRecord
    */
    @GetMapping("/{id}")
    public R<UcpConversationRecord> get(@PathVariable String id) {
        return R.ok(ucpConversationRecordService.getById(id));
    }


    /**
    * 分页查询信息
    *
    * @param  分页对象
    * @return 分页对象
    */
    @GetMapping("/page")
    public R<IPage> getPage(Page page, UcpConversationRecord ucpConversationRecord) {
        IPage p = ucpConversationRecordService.page(page, Wrappers.query(ucpConversationRecord));
        return R.ok( p );
    }

    /**
     * 添加
     * @param  ucpConversationRecord  实体
     * @return success/false
     */
    @PostMapping
    public R add(@RequestBody UcpConversationRecord ucpConversationRecord) {
        return R.ok(ucpConversationRecordService.save(ucpConversationRecord));
    }

    /**
     * 删除
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable String id) {
        UcpConversationRecord ucpConversationRecord = new UcpConversationRecord();
        ucpConversationRecord.setId(id);
        ucpConversationRecord.setGmtModifiedDate( new Date());
        ucpConversationRecord.setDelFlag(CommonConstants.STATUS_DEL);
        return R.ok(ucpConversationRecordService.updateById(ucpConversationRecord));
    }

    /**
     * 编辑
     * @param  ucpConversationRecord  实体
     * @return success/false
     */
    @PutMapping
    public R<Boolean> edit(@RequestBody UcpConversationRecord ucpConversationRecord) {
        ucpConversationRecord.setGmtModifiedDate( new Date());
        return R.ok(ucpConversationRecordService.updateById(ucpConversationRecord));
    }

    @ResponseBody
    @RequestMapping(value = "/getListByJsonApi", method = RequestMethod.GET , produces = "application/json;charset=UTF-8" )
    public List getListByJsonApi( @RequestParam Map<String, Object> params ){
        return  ucpConversationRecordService.queryListByJson( params );
    }
}
